package cn.itcast.jdbc;

import java.sql.Connection;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ParameterMetaTest {
	
	public static void main(String[] args) throws SQLException {
		read("select * from user where name=? and birthday<? and money>?", null);
	}
	
	static void read(String sql, Object[] params) throws SQLException {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			conn = JdbcUtils.getConnection();
			ps = conn.prepareStatement(sql);
			ParameterMetaData pmd = ps.getParameterMetaData();
			int count = pmd.getParameterCount();
			for (int i = 1; i <= count; i++) {
				System.out.print(pmd.getParameterClassName(i) + "\t");
				System.out.print(pmd.getParameterType(i) + "\t");
				System.out.println(pmd.getParameterTypeName(i) + "\t");
			}

		} finally {
			JdbcUtils.free(rs, ps, conn);
		}
	}

}
